package com.mytomcat.catalina.net;

import com.mytomcat.catalina.connector.Connector;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * endpoint抽象类
 *
 * @author supu
 * @date 2019-04-22 13:38
 **/
public abstract class AbstractEndpoint {
    private static final int CORE_POOL_SIZE = 10;
    private static final int MAXMIUM_POOL_SIZE = 200;


    private int port;
    private String address;
    private String url;
    private String domain;
    private Executor executor;
    private Connector connector;

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public Connector getConnector() {
        return connector;
    }

    public void setConnector(Connector connector) {
        this.connector = connector;
    }

    public void createExecutor() {
        CustomThreadFactory threadFactory = new CustomThreadFactory("endpoint");
        executor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXMIUM_POOL_SIZE, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), threadFactory);
    }

    public Executor getExecutor() {
        return executor;
    }

    public abstract void start();
}
